@model PocketPals.Models.BalanceViewModel

@{
    ViewData["Title"] = "余额信息";
}

@* Modified container: Removed min-vh-100 to prevent forced full height *@
<div class="container d-flex flex-column justify-content-center align-items-center">
    @* This row now acts as the content block to be centered *@
    <div class="row justify-content-center w-100"> @* Added w-100 to ensure row takes available width *@
        <div class="col-lg-8 col-md-10"> @* Adjust col-* classes as needed for desired width *@

            <div class="text-center mb-4">
                @* Increased title size from display-4 to display-3 *@
                <h1 class="display-3">当前余额</h1>
            </div>

            @* Add position-relative to the card for absolute positioning context *@
            <div class="card text-center shadow-sm mb-5 position-relative">
                @* --- Moved Add Transaction Button Inside Card --- *@
                @if (User.Identity.IsAuthenticated)
                {
                    @* Position the button top-right with padding (changed start-0 to end-0) *@
                    <div class="position-absolute top-0 end-0 p-2">
                        <a asp-controller="Transaction" asp-action="Create" class="btn btn-primary btn-sm" title="添加交易记录">
                            <i class="fas fa-plus"></i> @* Optionally remove text for smaller button *@
                        </a>
                    </div>
                }
                else
                {
                     @* Position the login button top-right with padding (changed start-0 to end-0) *@
                     <div class="position-absolute top-0 end-0 p-2">
                         <a asp-controller="Auth" asp-action="Login" asp-route-returnUrl="@Context.Request.Path" class="btn btn-secondary btn-sm" title="登录后添加">
                             <i class="fas fa-sign-in-alt"></i>
                         </a>
                     </div>
                }

                @* Add padding-top to card-body to avoid overlap with the button *@
                <div class="card-body p-4 pt-5">
                    @* Ensured balance amount uses display-1 for largest size *@
                    <h1 class="display-1 fw-bold text-primary mb-3">¥ @Model.CurrentBalance.Amount.ToString("N2")</h1>
                    <p class="card-text text-muted mb-1">最后更新时间: @Model.CurrentBalance.UpdatedAt.ToString("yyyy-MM-dd HH:mm:ss")</p>

                    @if (Model.CurrentBalance.OperationAmount != 0)
                    {
                        <hr class="my-3">
                        @* Updated this section to use properties from BalanceViewModel *@
                        <div class="mb-2">
                            <span class="fw-bold">最近操作:</span>
                            @if (Model.CurrentBalance.OperationAmount > 0)
                            {
                                <span class="text-success fw-bold ms-1">+@Model.CurrentBalance.OperationAmount.ToString("N2")</span>
                            }
                            else
                            {
                                <span class="text-danger fw-bold ms-1">@Model.CurrentBalance.OperationAmount.ToString("N2")</span>
                            }
                            @* Display Reason using LastTransactionReason from ViewModel *@
                            @if (!string.IsNullOrEmpty(Model.LastTransactionReason))
                            {
                                <span class="text-muted small ms-2">(原因: @Model.LastTransactionReason)</span>
                            }
                            @* Display Operator using LastTransactionOperator from ViewModel *@
                            @if (!string.IsNullOrEmpty(Model.LastTransactionOperator))
                            {
                                <span class="text-muted small ms-2">[@Model.LastTransactionOperator]</span>
                            }
                        </div>
                        <p class="card-text text-muted small mb-0">操作前: ¥ @Model.CurrentBalance.BeforeAmount.ToString("N2") | 操作后: ¥ @Model.CurrentBalance.AfterAmount.ToString("N2")</p>
                    }
                </div>
            </div>

            @* --- Removed the original button div from here --- *@

        </div> @* End of col-* div *@
    </div> @* End of row div *@
</div>